package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyServerServerRouteCloseTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteContext;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteType;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.ServerProxyRoute;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;

@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleDistributeHttpClientProxyServerServerRouteCloseTypeAdvanced extends
        AbstractHandleHttpDistributeClientProxyServerServerRouteCloseTypeAdvanced<NettyProxyMsg> {


    /**
     * 处理当前数据
     *
     * @param nettyChannelContext       当前通道
     * @param nettyProxyMsg 通道数据
     */
    @Override
    protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {

        byte[] data = nettyProxyMsg.getData();
        ServerProxyRoute serverProxyRoute = JSON.parseObject(data, ServerProxyRoute.class);
        RouteType routeType = serverProxyRoute.getRouteType();
        String virtualIp = serverProxyRoute.getVirtualIp();
        String virtualPort = serverProxyRoute.getVirtualPort();
        RouteContext.removeRoute(virtualIp,virtualPort,routeType);


    }
}
